package la.bbs558.controller.user;

import cn.dev33.satoken.stp.StpUtil;
import la.bbs558.aop.valid.Check;
import la.bbs558.controller.base.BaseController;
import la.bbs558.controller.base.Result;
import la.bbs558.entity.UserConfig;
import la.bbs558.service.UserConfigService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * @Classname UserController
 * @Description 用户配置
 * @Date 2023/12/15 10:27
 * @Created by weihanmin
 */
@RestController
@RequestMapping("user/config")
@Check
@RequiredArgsConstructor
public class UserConfigController extends BaseController {

    private final UserConfigService userConfigService;

    @GetMapping("info")
    public Result<?> info() {
        UserConfig userConfig = userConfigService.lambdaQuery()
                .eq(UserConfig::getUserId, StpUtil.getLoginIdAsLong())
                .one();
        return Result.success(userConfig);
    }

    @PostMapping("update")
    public Result<?> update(@RequestBody UserConfig userConfig) {
        userConfig.setUserId(StpUtil.getLoginIdAsLong());
        userConfigService.updateById(userConfig);
        return Result.success();
    }

}
